package Classe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;

public class ListReservationItem extends Observable implements Collection<ReservationItem> {
	private ArrayList<ReservationItem> m_ListReservationItem;
	public ListReservationItem(){
		m_ListReservationItem = new ArrayList<ReservationItem>();
	}
	@Override
	public boolean add(ReservationItem pReservationItem) {	
		Boolean returnValue = false;
		if (isValid(pReservationItem) && pReservationItem != null ) 		
		returnValue = m_ListReservationItem.add(pReservationItem);
		setChanged();
		notifyObservers(returnValue);
		return returnValue;
	}

	@Override
	public boolean addAll(Collection<? extends ReservationItem> pCollection) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void clear() {
		m_ListReservationItem.clear();		
	}
	
	@Override
	public boolean contains(Object o) {
		return m_ListReservationItem.contains(o);
	}
	public ReservationItem getReservationItem(int indexReservationItem) {
		return m_ListReservationItem.get(indexReservationItem);
	}
	@Override
	public boolean containsAll(Collection<?> pCollection) {
		return m_ListReservationItem.containsAll(pCollection);
	}

	@Override
	public boolean isEmpty() {
		return m_ListReservationItem.isEmpty();
	}

	@Override
	public Iterator<ReservationItem> iterator() {
		return m_ListReservationItem.iterator();
	}

	@Override
	public boolean remove(Object o) {
		Boolean returnValue = false;
		returnValue = m_ListReservationItem.remove(o);
		return returnValue;
	}

	@Override
	public boolean removeAll(Collection<?> pCollection) {
		Boolean returnValue = false;
		returnValue = m_ListReservationItem.removeAll(pCollection);
		return returnValue;
	}

	@Override
	public boolean retainAll(Collection<?> pCollection) {
		Boolean returnValue = false;
		returnValue = m_ListReservationItem.retainAll(pCollection);
		return returnValue;
	}

	@Override
	public int size() {
		return m_ListReservationItem.size();
	}

	@Override
	public Object[] toArray() {
		return m_ListReservationItem.toArray();
	}

	@Override
	public <T> T[] toArray(T[] pTableau) {
		return toArray(pTableau);
	}
	public boolean isValid(ReservationItem pReservationItem){
		return Agenda.getInstance().canAddReservationItem(pReservationItem);
	} 
	public void addObserverItem(Observer o)
	{
		if(size() <= 0)
			return;
		for (ReservationItem current : m_ListReservationItem) {
			current.addObserver(o);
		}
	}
	public void getData()
	{
		if(size() <= 0)
			return;
		for (ReservationItem current : m_ListReservationItem) {
			current.DeclancherObserver();
		}
	}
}
